import { NextApiRequest, NextApiResponse } from "next";

import { getDatasets } from "@/services";

async function getDatasetList(
  req: NextApiRequest,
  res: NextApiResponse<APIRes>
) {
  const result = await getDatasets(req);
  res.status(result.success ? 200 : 400).json(result);
}

export default async function handler(
  req: NextApiRequest,
  res: NextApiResponse<APIRes>
) {
  if (req.method === "GET") {
    getDatasetList(req, res);
  } else {
    res
      .status(405)
      .json({ success: false, data: {}, message: "Method not allowed" });
  }
}
